package com.de.juxfux.io;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.de.juxfux.ManageDbActivity;
import com.de.juxfux.R;
import com.de.juxfux.settings.SettingsActivity;


public class AnalyzerDialog extends DialogFragment {
	private Spanned message;
	private int positiveButton = 0;
	private int negativeButton = 0;
	
	public AnalyzerDialog() {
		super();
	}

	public void setPositiveButton(int positiveButton) {
		this.positiveButton = positiveButton;
	}

	public void setNegativeButton(int negativeButton) {
		this.negativeButton = negativeButton;
	}

	public Spanned getMessage() {
		return message;
	}

	public void setMessage(Spanned message) {
		this.message = message;
	}

	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
		LayoutInflater inflater = LayoutInflater.from(getActivity());
        View view = inflater.inflate(R.layout.dialog, null);
        TextView textview = (TextView) view.findViewById(R.id.textmsg);
        textview.setText(message);
        textview.setMaxLines(Integer.MAX_VALUE);
        textview.setEllipsize(null);
		
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(view);

        if (positiveButton != 0) {
        	builder
        	.setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
        		public void onClick(DialogInterface dialog, int id) {
        			dismiss(); //TODO: oder dismiss() hinter startImport() !? ---> testen
        			ManageDbActivity a = (ManageDbActivity) getActivity();
        			ExcelReader er = new ExcelReader(a, a.getPbHandler());
        			er.startImport(SettingsActivity.getImportDir(a));
        		}
        	});
        }
        
        if (negativeButton != 0) {
        	builder.setNegativeButton(negativeButton, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                	   dismiss();
                   }
               });
        }
        
        return builder.create();
    }
}